import json,chardet,os,time

#模拟手指从上往下滑动
downSwip="adb shell input swipe 400 500 400 1300 200"
adbCmd=downSwip

skipValue={"requestId","result"}
testMode=2
def readFile(fileName="test.txt"):
    with open(fileName,"rb") as f:
        data=f.read()
        strType=chardet.detect(data)
        print(strType)
        realData=data.decode(strType['encoding'])
        return realData

def saveFile(data):
    with open("test2.txt","w") as f:
        f.write(data)

def changeDicToNull(data,totalData):
    for i in data.keys():
        if type(data[i])==dict:
            changeDicToNull(data[i],totalData)
        elif type(data[i])==list:
            changeListToNull(data[i],totalData)
        else:
            print(i,data[i])
        isSkip=False
        for key in skipValue:
            if key==i:
                isSkip=True
        if not isSkip:
            data[i]=None
        doSomeThing(totalData)

def changeListToNull(list,totalData):
    for bean in list:
        if type(bean)==dict:
            changeDicToNull(bean,totalData)
        elif type(bean)==list:
            changeListToNull(bean,totalData)
        else:
            print(bean)
        bean=None
        doSomeThing(totalData)

def doSomeThing(totalData):
    saveFile(json.dumps(totalData))
    os.system(adbCmd)
    if testMode=="1":
        input()
    #time.sleep(1)

if __name__ == "__main__":
    print("如果使用手动模式请输入1，如果使用自动模式请输入2")
    testMode=input()
    data=readFile()
    if data!=None:        
        user_dic = json.loads(data)
        print(user_dic)
        changeDicToNull(user_dic,user_dic)
        print(user_dic)
            # input()